﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using WMSABL;
using WMSABL.SY;
using WMSAML.SY;
using ElectronicWMSA.Comm.ClassFiles;
using WMSAML.Warehouse;
using ElectronicWMSA.Comm.Forms.Message;

namespace ElectronicWMSA.Warehouse
{
    public partial class List_PickNoMapFrm : Form
    {
        #region
        private string strWhere = "";
        PublicDataSet bll_PublicDataSet = new PublicDataSet();
        public List_PickNoMapFrm()
        {
            InitializeComponent();
            this.strWhere = "";
            this.DBindCombox();
            this.page1.PageCurrent = 1;
            this.page1.PageSize = 30;
            this.page1.Bind();
        }
        #endregion

        #region
        public void DBindCombox()
        {
            if (true)
            {
                DataSet ds = new DataSet();
                ds = bll_PublicDataSet.GetDataSet("PD_PickingList", "");
                DataTable dt = ds.Tables[0];
                DataRow dr = dt.NewRow();
                dr["NID"] = "0";
                dr["PickNO"] = "--请选择--";
                dt.Rows.InsertAt(dr, 0);
                this.comboBox1.DataSource = dt;
                this.comboBox1.ValueMember = "NID";
                this.comboBox1.DisplayMember = "PickNO";
            }
            if (true)
            {
                DataSet ds = new DataSet();
                ds = bll_PublicDataSet.GetDataSet("select '1' NID,UserCode from PD_PickingList group by UserCode ");
                DataTable dt = ds.Tables[0];
                DataRow dr = dt.NewRow();
                dr["NID"] = "0";
                dr["UserCode"] = "--请选择--";
                dt.Rows.InsertAt(dr, 0);
                this.comboBox2.DataSource = dt;
                this.comboBox2.ValueMember = "NID";
                this.comboBox2.DisplayMember = "UserCode";
            }
        }
        #endregion

        #region DBindPage
        private int DBindPage()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "PD_PickingMap";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.page1.PageCurrent;
            pageData.PageSize = this.page1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.page1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.page1.bindingNavigator.BindingSource = page1.bindingSource;
            this.dataGridViewUserList.AutoGenerateColumns = false;
            this.dataGridViewUserList.DataSource = this.page1.bindingSource;
            this.dataGridViewUserList.ClearSelection();
            this.dataGridViewUserList.CurrentCell = null;
            return pageData.TotalCount;
        }
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindPage();
        }
        #endregion

        #region 查询
        private void btnUserSearch_Click(object sender, EventArgs e)
        {
            if (!SystemVariable.VaildationPermission("查询")) return;
            strWhere = " 1=1 ";
            if (this.comboBox1.Text.Trim() != "" && this.comboBox1.Text.Trim() != "--请选择--")
                this.strWhere += " AND PickNO='" + this.comboBox1.Text.Trim() + "' ";
            if (this.comboBox2.Text.Trim() != "--请选择--" && this.comboBox2.Text.Trim() != "")
                this.strWhere += " AND UserCode='" + this.comboBox2.Text.Trim() + "' ";
            this.page1.Bind();
        }
        #endregion
        PD_PickingMap_BLL blll = new PD_PickingMap_BLL();
        PD_PickingMapEntity entitys = new PD_PickingMapEntity();
        private void dataGridViewUserList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                if (this.dataGridViewUserList.Rows.Count != 0)
                {
                    if (e.ColumnIndex != -1 && this.dataGridViewUserList.CurrentCell.ColumnIndex == 1)
                    {
                        entitys = blll.Getentity(dataGridViewUserList.CurrentRow.Cells["PickNO"].Value.ToString(), dataGridViewUserList.CurrentRow.Cells["UserName"].Value.ToString());
                        if (entitys != null)
                        {
                            List_PickNoMapShowFrm frm = new List_PickNoMapShowFrm(entitys, 1);
                            frm.ShowDialog();
                        }
                    }

                    else if (e.ColumnIndex != -1 && this.dataGridViewUserList.CurrentCell.ColumnIndex == 2)
                    {
                        entitys = blll.Getentity(dataGridViewUserList.CurrentRow.Cells["PickNO"].Value.ToString(), dataGridViewUserList.CurrentRow.Cells["UserName"].Value.ToString());
                        if (entitys != null)
                        {
                            List_PickNoMapShowFrm frm = new List_PickNoMapShowFrm(entitys, 2);
                            frm.ShowDialog();
                        }
                    }

                    else if (e.ColumnIndex != -1 && this.dataGridViewUserList.CurrentCell.ColumnIndex == 0)
                    {
                        if (MessageClass.enquire("确认删除此路线图？") == DialogResult.OK)
                        {
                            string pickNO = dataGridViewUserList.CurrentRow.Cells["PickNO"].Value.ToString();
                            string CodeNO = dataGridViewUserList.CurrentRow.Cells["UserName"].Value.ToString();
                            blll.Delete(pickNO, CodeNO);
                        }
                    }
                }
            }
        }

        #region 序号
        private void dataGridViewUserList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridViewUserList.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridViewUserList.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        #endregion

        #region 退出
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }

        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }

        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }
        #endregion


    }
}
